import {
  policy
} from './policy'
let OSS = require('ali-oss');

let client = new OSS({
    region: 'oss-cn-beijing',
    accessKeyId: 'LTAI5tBcU9jHpCEpUXbYSDTe',
    accessKeySecret: 'jSLpJGCNHwSWVEcNP1mCOloZKCkxCP',
    bucket: 'wwy-jiufen',
  });

export async function uploadBuffer(res) {
  // debugger
  console.log("res:", res)
  
  console.log(client)
  try {
    //   let fileName=res.data.path;
    //   console.log("fileName:",fileName);
    let result = await client.put(res.data.path, new Buffer(res.val));
    console.log("上传成功！")
    // console.log("result:", result);
    return res.data.path;
    // downLoadBuffer(res.data.path);
  } catch (e) {
    console.log(e);
  }
}

export async function downLoadBuffer (filename) {
    console.log("下载成功！")
    try {
      console.log("filename:",filename);
      let result = await client.get(filename);
      // console.log(result.content.toString());
      return result.content.toString();
    } catch (e) {
      console.log(e);
    }
}
